#!/usr/bin/env bash
# An example script of routine QRPBBB usage..
# Let's assume that boot.sh and qrpbbb_schedule.py are already been taken care of.
# Rather than this script, there's running from cron.

counters=( 0 0 0 0 )
#limits=( 120 240 960 240 )  # suggested APRS
limits=( 40 80 960 120 ) # suggested Simplex
cmds=( "./qrpbbb_iwant.py" "./qrpbbb_ihave.py 1" "./qrpbbb_ihave.py" "./qrpbbb_beacon.py " )

cd ~/qrpbbb
dt="0"

count=0
while [ "x${counters[count]}" != "x" ]; do ((count++)); done; ((count--))

./qrpbbb_beacon.py
./qrpbbb_ihave.py

while true
do
    i=0
    while [ $i -le $count ]
    do
	counters[i]=$((${counters[i]}+1))
	if [ ${counters[i]} -eq ${limits[i]} ];
	then
	    ${cmds[i]}
	    counters[i]=0
	fi
	((i++))
    done

    sleep 15

    t=`stat -c %Y /var/spool/packet/recv`
    if [ $(( $t - $dt )) == 0 ]; then continue; fi
    dt=$t

    ./qrpbbb_process.py
    ./qrpbbb_queuecheck.py

done
